﻿using UnityEngine;
using System.Collections;

public class PauseMenu : MonoBehaviour {

    bool pause;

    public GameObject[] disabled;
    public GameObject[] enabled;

    public GameObject GlassFx;
    public MonoBehaviour[] disabledCode;

    public Movement move;
	void Update () 
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!pause)
            {
                if (!GetComponent<Movement>().enabled)
                    GlassFx.SetActive(false);

                move.pause = true;

                Time.timeScale = 0;
                foreach (GameObject current in disabled)
                {
                    current.SetActive(false);
                }
                foreach (GameObject current in enabled)
                {
                    current.SetActive(true);
                }
                foreach (MonoBehaviour current in disabledCode)
                {
                    current.enabled = false;
                }
            }
            else
            {
                move.pause = false;

                Time.timeScale = 1;
                foreach (GameObject current in disabled)
                {
                    current.SetActive(true);
                }
                foreach (GameObject current in enabled)
                {
                    current.SetActive(false);
                }
                foreach (MonoBehaviour current in disabledCode)
                {

                    current.enabled = true;
                }
            }

            pause = !pause;
        }
	}
}
